package tienda.zapateria.siszap.gui.control;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import javax.swing.FocusManager;
import javax.swing.JOptionPane;
import org.rx.cr.gui.JInternalFrameUC;
import org.rx.cr.util.Utilitarios;
import static org.rx.cr.util.Utilitarios.alinearDatosColumnaTablaCentro;
import static org.rx.cr.util.Utilitarios.disableComponent;
import static org.rx.cr.util.Utilitarios.enableComponent;
import static org.rx.cr.util.Utilitarios.formateaAnchoColumnaTabla;
import static org.rx.cr.util.Utilitarios.resetComponents;
import tienda.zapateria.siszap.be.BEProveedor;
import tienda.zapateria.siszap.be.BEUbigeo;
import tienda.zapateria.siszap.bl.BLProveedor;
import tienda.zapateria.siszap.gui.JF_Principal;
import tienda.zapateria.siszap.gui.control.model.ModelProveedor;
import tienda.zapateria.siszap.util.UtilUbigeo;

public class JIF_AdministrarProveedor extends JInternalFrameUC {

    JF_Principal parent;
    BEProveedor be;
    BLProveedor bl;
    ModelProveedor model;

    UtilUbigeo utilUbigeo;

    public JIF_AdministrarProveedor(JF_Principal parent) {
        initComponents();
        this.parent = parent;
        bl = new BLProveedor(parent.getConf());
        model = new ModelProveedor();
        jtProveedor.setModel(model);
        personalizaVistaTabla();

        utilUbigeo = new UtilUbigeo(parent.getConf());
        _init();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        txfBuscar = new javax.swing.JTextField()
        {
            @Override
            protected void paintComponent(java.awt.Graphics g) {
                super.paintComponent(g);
                if(isEnabled() && getText().isEmpty() && ! (FocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == this)){
                    Graphics2D g2 = (Graphics2D)g.create();
                    g2.setColor(Color.gray);
                    g2.setFont(getFont().deriveFont(Font.ITALIC));
                    g2.drawString("Ingrese Nombre y/o Razon social",5,18);
                    g2.dispose();
                }
            }
        };
        jScrollPane1 = new javax.swing.JScrollPane();
        jtProveedor = new javax.swing.JTable();
        jbBuscar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txfRazonSocial = new javax.swing.JTextField();
        txfRuc = new javax.swing.JTextField();
        txfTelefono = new javax.swing.JTextField();
        txfCorreo = new javax.swing.JTextField();
        txfDireccion = new javax.swing.JTextField();
        jcbDepartamento = new javax.swing.JComboBox();
        jcbProvincia = new javax.swing.JComboBox();
        jcbDistrito = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jbEditar = new javax.swing.JButton();
        jbGuardar = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jbAgregar = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "BUSCAR PROVEEDOR", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jtProveedor.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jtProveedor);

        jbBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/Buscar.png"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(txfBuscar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbBuscar)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jbBuscar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txfBuscar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "PROVEEDOR", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel1.setText("Razón social :");

        jLabel2.setText("R.U.C.");

        jLabel3.setText("Teléfono :");

        jLabel4.setText("Correo :");

        jLabel5.setText("Dirección :");

        jcbDepartamento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbDepartamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbDepartamentoActionPerformed(evt);
            }
        });

        jcbProvincia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbProvincia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbProvinciaActionPerformed(evt);
            }
        });

        jcbDistrito.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbDistrito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbDistritoActionPerformed(evt);
            }
        });

        jLabel6.setText("Departamento :");

        jLabel7.setText("Provincia :");

        jLabel8.setText("Distrito :");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcbDistrito, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jcbProvincia, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jcbDepartamento, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txfRazonSocial, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)
                    .addComponent(txfRuc)
                    .addComponent(txfTelefono)
                    .addComponent(txfCorreo)
                    .addComponent(txfDireccion, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(12, 12, 12))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txfRazonSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txfRuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txfTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txfCorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbDepartamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbDistrito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jbEditar.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jbEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/Modificar_Min.png"))); // NOI18N
        jbEditar.setText("EDITAR");
        jbEditar.setEnabled(false);
        jbEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbEditar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        jbGuardar.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jbGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/Guardar_Min.png"))); // NOI18N
        jbGuardar.setText("GUARDAR");
        jbGuardar.setEnabled(false);
        jbGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbGuardar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        jbCancelar.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/Cancelar_Min.png"))); // NOI18N
        jbCancelar.setText("CANCEL");
        jbCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbCancelar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        jbAgregar.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jbAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tienda/zapateria/siszap/imagen/Nuevo.png"))); // NOI18N
        jbAgregar.setText("NUEVO");
        jbAgregar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbAgregar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbAgregar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jbAgregar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbEditar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbCancelar)
                        .addContainerGap(42, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbAgregar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbEditar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbGuardar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbCancelar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jcbDepartamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbDepartamentoActionPerformed
        // TODO add your handling code here:
        eventoComboDepartamento();
    }//GEN-LAST:event_jcbDepartamentoActionPerformed

    private void jcbProvinciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbProvinciaActionPerformed
        // TODO add your handling code here:
        eventoComboProvincia();
    }//GEN-LAST:event_jcbProvinciaActionPerformed

    private void jcbDistritoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbDistritoActionPerformed
        // TODO add your handling code here:
        eventoComboDistrito();
    }//GEN-LAST:event_jcbDistritoActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbAgregar;
    private javax.swing.JButton jbBuscar;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbEditar;
    private javax.swing.JButton jbGuardar;
    private javax.swing.JComboBox jcbDepartamento;
    private javax.swing.JComboBox jcbDistrito;
    private javax.swing.JComboBox jcbProvincia;
    private javax.swing.JTable jtProveedor;
    private javax.swing.JTextField txfBuscar;
    private javax.swing.JTextField txfCorreo;
    private javax.swing.JTextField txfDireccion;
    private javax.swing.JTextField txfRazonSocial;
    private javax.swing.JTextField txfRuc;
    private javax.swing.JTextField txfTelefono;
    // End of variables declaration//GEN-END:variables

    @Override
    public void _cargarCombos() throws Exception {
        utilUbigeo.defaultSelectedUbigeo("ayacucho", "huamanga", "ayacucho", jcbDepartamento, jcbProvincia, jcbDistrito);

    }

    @Override
    public void _agregaValidadoresControl() {
        Utilitarios.addEnterDoclickEvent(new Object[][]{{txfBuscar, jbBuscar}});
        _addOperationEventsButtons(jbAgregar, jbEditar, jbGuardar, jbCancelar);
        _addRestoreDataEventsTable(jtProveedor);
        _addSearchEventsButton(jbBuscar);
        Utilitarios.addCharacterValidatorEvent(new Object[][]{ //{txfEstablecimientoSalud, ALFABETICO_CM, 160},
        //         {txfNumMaquinas, NUMERICO, 20},
        //        {txfNumTrabajadores, NUMERICO, 20},
        //                    {txfTelefono, NUMERICO, 15}
        });
    }

    @Override
    public boolean _isDatosValidosBE() {
        return Utilitarios.isDatosLlenos(new Object[][]{
            {txfRazonSocial, "Ingresar el nombre o la razón social del proveedor."}
// {txfEstablecimientoSalud, "Ingresar el nombre del establecimiento"},
        // {txfCodigoEstablecimiento, "Ingresar el código del establecimiento"},
        // {txfDireccion, "Ingresar la dirección del establecimiento"},
        });
    }

    @Override
    public int _registrarBE() throws Exception {
        try {
            be = new BEProveedor();
            be.setRazonsocial(txfRazonSocial.getText());
            be.setDireccion(txfDireccion.getText());
            be.setCorreo(txfCorreo.getText());
            be.setRuc(txfRuc.getText());
            be.setTelefono(txfTelefono.getText());
            be.setUbigeoid(((BEUbigeo) jcbDistrito.getSelectedItem()).getUbigeoid());

            bl.registrar(be);
            JOptionPane.showMessageDialog(this, "Registro exitoso. ", "Administrar proveedor", JOptionPane.INFORMATION_MESSAGE);

            return 1;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error en el registro: " + e, "Atención", JOptionPane.ERROR_MESSAGE);
            return 0;
        }
    }

    @Override
    public int _guardarCambiosBE() throws Exception {
        try {
            be = model.get(jtProveedor.getSelectedRow());
            be.setRazonsocial(txfRazonSocial.getText());
            be.setDireccion(txfDireccion.getText());
            be.setCorreo(txfCorreo.getText());
            be.setRuc(txfRuc.getText());
            be.setTelefono(txfTelefono.getText());
            be.setUbigeoid(((BEUbigeo) jcbDistrito.getSelectedItem()).getUbigeoid());

            bl.actualizarRegistro(be);
            JOptionPane.showMessageDialog(this, "Actualización exitosa. ", "Administrar proveedor.", JOptionPane.INFORMATION_MESSAGE);

            return 1;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error en la actualización: " + e, "Atención", JOptionPane.ERROR_MESSAGE);
            return 0;
        }
    }

    @Override
    public void _listarBEs() throws Exception {
        model.addAll(bl.buscarReferencia(txfBuscar.getText()));
        personalizaVistaTabla();
    }

    @Override
    public void _recuperarDatosBE() throws Exception {
        if (jtProveedor.getSelectedRow() >= 0) {
            be = model.get(jtProveedor.getSelectedRow());
            txfCorreo.setText(be.getCorreo());
            txfDireccion.setText(be.getDireccion());
            txfRazonSocial.setText(be.getRazonsocial());
            txfRuc.setText(be.getRuc());
            txfTelefono.setText(be.getTelefono());
            System.out.println("Esto es el id ubigeo : " + be.getUbigeoid());
            if (be.getUbigeoid() == 0) {
            } else {
                utilUbigeo.recuperarDatosUbigeo(be.getUbigeoid(), jcbDepartamento, jcbProvincia, jcbDistrito);
            }
            jbEditar.setEnabled(true);
        }
    }

    @Override
    public void _deshabilitarControlesDatos() {
        disableComponent(new Object[]{
            txfTelefono, txfRuc, txfRazonSocial, txfDireccion, txfCorreo,
            jcbDepartamento, jcbProvincia, jcbDistrito
        });
    }

    @Override
    public void _habilitarControlesDatos() {
        enableComponent(new Object[]{
            txfTelefono, txfRuc, txfRazonSocial, txfDireccion, txfCorreo,
            jcbDepartamento, jcbProvincia, jcbDistrito
        });
    }

    @Override
    public void _resetControls() {
        resetComponents(new Object[]{
            txfTelefono, txfRuc, txfRazonSocial, txfDireccion, txfCorreo,
            jcbDepartamento, jcbProvincia, jcbDistrito
        });
    }

    private void personalizaVistaTabla() {
        alinearDatosColumnaTablaCentro(0, jtProveedor);
        formateaAnchoColumnaTabla(0, jtProveedor, 249);
    }

    public void eventoComboDepartamento() {
        if (utilUbigeo != null && jcbDepartamento.getSelectedIndex() > 0) {
            utilUbigeo.eventoComboDepartamento(jcbDepartamento, jcbProvincia, jcbDistrito);
        }
    }

    public void eventoComboProvincia() {
        if (utilUbigeo != null && jcbProvincia.getSelectedIndex() > 0) {
            utilUbigeo.eventoComboProvincia(jcbDepartamento, jcbProvincia, jcbDistrito);
        }
    }

    public void eventoComboDistrito() {
        if (utilUbigeo != null && jcbDistrito.getSelectedIndex() > 0) {
            utilUbigeo.eventoComboDistrito(jcbDepartamento, jcbProvincia, jcbDistrito);
        }
    }
}
